package net.wenku8.reader.view.common

import androidx.compose.material3.AlertDialog
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.window.DialogProperties
import androidx.lifecycle.viewmodel.compose.viewModel
import net.wenku8.reader.ui.lite.LiteText
import net.wenku8.reader.ui.lite.LiteTitle

@Composable
fun ConfirmLayer(){
    val confirmViewModel = viewModel<ConfirmViewModel>()
    if (confirmViewModel.show){
        AlertDialog(
            onDismissRequest = { confirmViewModel.show = false },
            title = {
                if (confirmViewModel.title.isNotEmpty()){
                    LiteTitle(confirmViewModel.title)
                }
            },
            text = {
                LiteText(confirmViewModel.text)
            },
            confirmButton = {
                TextButton(onClick = {
                    confirmViewModel.event()
                    confirmViewModel.show = false
                }) {
                    LiteText("确认")
                }
            },
            dismissButton = {
                TextButton(onClick = { confirmViewModel.show = false }) {
                    LiteText("取消")
                }
            },
            properties = DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = false)
        )
    }
}